package leetcode100;

import java.util.LinkedList;

public class lc050 {

    public static void main(String[] args) {
        Tree tree = new Tree();
        TreeNode root = tree.root;
        new lc050().preVisit(root);
    }

    public void preVisit(TreeNode root) {
        if (root == null)
            return;
        LinkedList<TreeNode> stack = new LinkedList<>();
        stack.push(root);
        TreeNode cur = null;
        while(!stack.isEmpty()) {
            cur = stack.pop();
            System.out.print(cur.val+" ");
            if (cur.right!=null)  {
                stack.push(cur.right);
            }
            if (cur.left!=null) {
                stack.push(cur.left);
            }
        }
    }
}
